/**
 * 
 */
package com.sjzs.web.common;

import java.io.ByteArrayInputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;


/**
 * @deprecated:图片验证码
 * @author acer
 * @date 2013-7-18 下午03:16:23
 */
public class CodeImageAction extends BaseAction {
	//图片流
	private ByteArrayInputStream imageStream;
	private String securityCode;
	private String checkMsg;
	
	private String status;
	private String info;
	/**
	 * @return 验证码图片
	 * @description: 获取验证码图片
	 */
	public String execute() {
		//获取默认难度和长度的验证码
		String securityCode = SecurityCode.getSecurityCode();
		imageStream = SecurityImage.getImageAsInputStream(securityCode);
		HttpServletRequest req = getRequest();
		HttpSession session = req.getSession();
		session.setAttribute("SESSION_SECURITY_CODE", securityCode);
		return SUCCESS;
	}

	/**
	 * @return 验证码图片
	 * @description: 获取验证码图片
	 
	 */
	public String check() {
		HttpServletRequest req = getRequest();
		HttpSession session = req.getSession();
		if(securityCode==null){
			checkMsg="error";
			status="n";
			info="验证码错误";
			return SUCCESS;
		}
		checkMsg=null;
		if(session.getAttribute("SESSION_SECURITY_CODE").equals(securityCode.toLowerCase())){
			checkMsg="success";
			status="y";
			info="验证成功!";
		}else{
			checkMsg="error";
			status="n";
			info="验证码错误";
		}
		return SUCCESS;
	}

	/**
	 * @return the imageStream
	 */
	public ByteArrayInputStream getImageStream() {
		return imageStream;
	}

	/**
	 * @param imageStream the imageStream to set
	 */
	public void setImageStream(ByteArrayInputStream imageStream) {
		this.imageStream = imageStream;
	}

	/**
	 * @return the securityCode
	 */
	public String getSecurityCode() {
		return securityCode;
	}

	/**
	 * @param securityCode the securityCode to set
	 */
	public void setSecurityCode(String securityCode) {
		this.securityCode = securityCode;
	}

	/**
	 * @return the checkMsg
	 */
	public String getCheckMsg() {
		return checkMsg;
	}

	/**
	 * @param checkMsg the checkMsg to set
	 */
	public void setCheckMsg(String checkMsg) {
		this.checkMsg = checkMsg;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

}
